﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<OGS.Web.Models.Admin.CategoryListModel>" %>

<%@ Import Namespace="MvcPaging" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%= OGS.Utility.Helper.GetPageTitle("Category List") %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <ol class="breadcrumb">
                    <li><a href="/admin/manage-dashboard">Home</a></li>
                    <li class="active">Category List</li>
                </ol>
            </div>
            <div class="col-xs-12">
                <div class="well well-White">
                    <div class="bs-example form-horizontal">
                        <div class="form-group">
                            <div class="col-xs-8">
                                <%: Html.DropDownListFor(m => m.ParentCategoryID, new SelectList(Model.ParentCategories, "ID", "ComputedName"), new { @class = "form-control" })%>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-xs-8">
                                <%: Html.TextBoxFor(m => m.Name, new { @class = "form-control", @maxlength = "100", PlaceHolder = "Type to search Categories" })%>
                            </div>
                            <a class="btn btn-primary btnSearch">Search</a>
                        </div>
                        <div class="form-group">
                            <div class="col-xs-8" style="padding-top: 14px;">
                                <%= OGS.Utility.Helper.GetResultCount(Model.SearchAttributes) %>
                            </div>
                            <div class="col-xs-4" style="text-align: right;">
                                <a href="/admin/save-Category" class="btn btn-primary">Add New</a>
                            </div>
                        </div>
                    </div>

                    <div class="table-responsive">
                        <table class="table table-bordered table-striped dataTable">
                            <thead>
                                <%= OGS.Utility.Helper.RenderHeader("Code", true, "", 0) %>
                                <%= OGS.Utility.Helper.RenderHeader("Parent Category", true, "", 1) %>
                                <%= OGS.Utility.Helper.RenderHeader("Name", true, "", 2) %>
                                <%= OGS.Utility.Helper.RenderHeader("Name (Bengali)", false, "", 3) %>
                                <%= OGS.Utility.Helper.RenderHeader("Name (Hindi)", false, "", 4) %>
                                <%= OGS.Utility.Helper.RenderHeader("Display Order", false, "", 5) %>
                                <%= OGS.Utility.Helper.RenderHeader("Active", false, "60px", 6) %>
                                <%= OGS.Utility.Helper.RenderHeader("", false, "20px", 2) %>
                            </thead>
                            <tbody>
                                <% if (Model.Categories.Count > 0)
                                   {
                                       foreach (var item in Model.Categories)
                                       { %>
                                <tr>
                                    <td><%= item.Code %></td>
                                    <td><%= item.ParentCategoryName %></td>
                                    <td><%= item.CategoryLanguages[0].Name %></td>
                                    <td><%= item.CategoryLanguages[1].Name %></td>
                                    <td><%= item.CategoryLanguages[2].Name %></td>
                                    <td><%= item.DisplayOrder %></td>
                                    <td>
                                        <% if (item.IsActive)
                                           { %>
                                        <span class="glyphicon glyphicon-ok text-success" title="Active"></span>
                                        <% }
                                           else
                                           { %>
                                        <span class="glyphicon glyphicon-remove text-danger" title="Inactive"></span>
                                        <% } %>
                                    </td>
                                    <td><a href="/admin/save-Category/<%= item.ID %>" title="Edit"><i class="fa fa-edit"></i></a></td>
                                </tr>
                                <%      }
                                   }
                                   else
                                   {
                                %>
                                <tr>
                                    <td colspan="8" style="text-align: center;">No results found.</td>
                                </tr>
                                <%      
                                   }
                                %>
                            </tbody>
                        </table>
                    </div>
                    <% if (Model.SearchAttributes.TotalRecordCount > Model.SearchAttributes.RecordsPerPage)
                       { %>
                    <div class="row">
                        <div class="text-center">
                            <%: @Html.Pager(Model.SearchAttributes.RecordsPerPage, Model.SearchAttributes.CurrentPageNumber, Model.SearchAttributes.TotalRecordCount).Options(o =>  o.DisplayTemplate("BootstrapPagination")).Options(o => o.AddRouteValue("name", Model.Name)).Options(o => o.AddRouteValue("SortDirection", (int)Model.SearchAttributes.SortDirection)).Options(o => o.AddRouteValue("SortColumnIndex", (int)Model.SearchAttributes.SortColumnIndex))%>
                        </div>
                    </div>
                    <% } %>
                </div>
            </div>
        </div>
    </section>

    <script type="text/javascript">
        $(document).ready(function () {
            $(".btnSearch").click(function () {
                var name = $.trim($("#Name").val());
                if (name != "") {
                    location.href = "/admin/Category-list/?name=" + $("#Name").val() + "&parentcategory=" + $("#ParentCategoryID").val();
                } else {
                    location.href = "/admin/Category-list/?parentcategory=" + $("#ParentCategoryID").val();
                }
            });

            $("#Name").keypress(function (e) {
                if (e.which == "13") {
                    e.preventDefault();
                    $(".btnSearch").click();
                }
            });
        });
    </script>

</asp:Content>
